from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Base():
    def __init__(self):
        cap={
            "platformName": "Android",
            "appium:deviceName": "emulator-5554",
            "appium:automationName": "uiautomator2",
            "appium:appPackage": "com.kongfz.app",
            "appium:appActivity": ".home.mvvm.homepage.HomeActivity",
            "appium:noReset": True
             }
        # 远程链接
        self.driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        # 第一种等待方式
        self.driver.implicitly_wait(20)
    def find_ele(self,loc):
        ele=self.driver.find_element(*loc)
        return ele
    # 第二种等待方式
    def find_ele_wait(self,loc):
        ele=WebDriverWait(self.driver,20).until(EC.element_to_be_clickable(20))
        return ele
    # 轻敲
    def qingqiao(self,x,y):
        self.driver.tap(x,y)
    # 滑动
    def hua(self,a,b,c,d):
        self.driver.swipe(a,b,c,d)
    # 截屏
    def jie(self,a):
        self.driver.save_screenshot(a)
    # 返回
    def fan(self):
        self.driver.back()
    # 退出
    def exit(self):
        self.driver.quit()





